Author: Christian Themin

Geo-visualization: Map of Australia

In [1]:
# Import library that will be useful for the mapping and analysis
import numpy as np 
import pandas as pd
import folium
from geopy.geocoders import Nominatim
In [2]:
# Define the map of Australia using geolocator
address = 'Australia'

geolocator = Nominatim(user_agent="map_explorer")
location = geolocator.geocode(address)
latitude = location.latitude
longitude = location.longitude
print('The geograpical coordinate of Australia is {}, {}.'.format(latitude, longitude))
The geograpical coordinate of Australia is -24.7761086, 134.755.
In [3]:
# Draw the map of Australia
Australia = folium.Map(location=[-24.776, 134.755], zoom_start = 4)

# display the map
Australia
Out[3]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [4]:
# Zoom in to Melbourne
Melbourne = folium.Map(location=[-37.814, 144.9632], zoom_start = 10)

# display the map
Melbourne
Out[4]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [39]:
# Open the Suburbs of Victoria file
Victoria = pd.read_csv("Victoria.csv")
Victoria.drop(['Unnamed: 0'], axis=1, inplace = True)
Victoria.head()
Out[39]:
Latitude Longitude Suburb Postcode
0 -37.813 144.961 Melbourne 3000
1 -37.813 144.984 East Melbourne 3002
2 -37.809 144.947 West Melbourne 3003
3 -37.842 144.976 Melbourne 3004
4 -37.818 144.944 Docklands 3008
In [42]:
# Add markers to map
for lat, lng, suburb, postcode in zip(Victoria['Latitude'], Victoria['Longitude'], Victoria['Suburb'], Victoria['Postcode']):
    label = '{}, {}'.format(postcode, suburb)
    label = folium.Popup(label, parse_html=True)
    folium.CircleMarker(
        [lat, lng],
        radius=5,
        popup=label,
        color='blue',
        fill=True,
        fill_color='#3186cc',
        fill_opacity=0.7,
        parse_html=False).add_to(Melbourne)  
    
Melbourne
Out[42]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [9]:
import os
import json
import requests


url = 'https://raw.githubusercontent.com/python-visualization/folium/master/examples/data'
vis1 = json.loads(requests.get(f'{url}/vis1.json').text)
vis2 = json.loads(requests.get(f'{url}/vis2.json').text)
vis3 = json.loads(requests.get(f'{url}/vis3.json').text)
In [41]:
# Add popup marker on the map
m = folium.Map(
    location=[-37.814, 144.9632],
    zoom_start=13    
)

folium.Marker(
    location=[-37.813, 144.961],
    popup=folium.Popup(max_width=450).add_child(
        folium.Vega(vis1, width=450, height=250))
).add_to(m)


folium.Marker(
    location=[-37.809, 144.947],
    popup=folium.Popup(max_width=450).add_child(
        folium.Vega(vis2, width=450, height=250))
).add_to(m)


folium.Marker(
    location=[-37.8180, 144.944],
    popup=folium.Popup(max_width=450).add_child(
        folium.Vega(vis3, width=450, height=250))
).add_to(m)


m
Out[41]:
Make this Notebook Trusted to load map: File -> Trust Notebook

We can combine any dataset with location details onto the map to check what activity has been going on in the city

In [ ]: